// Created by Roman Novitsky on 25.05.2009


#region Imported Namespaces


using System.Windows.Input;

using WtfManager.Framework;
using WtfManager.UIManager.Commands;


#endregion


namespace WtfManager.EditingHistory
{
  public class RedoCommandHandler: Service, ICommandHandler
  {
    #region Fields


    private EditingHistoryService _historyService;


    #endregion


    #region Properties/Indexers


    public ICommand Command
    {
      get
      {
        return ApplicationCommands.Redo;
      }
    }


    public override string Description
    {
      get
      {
        return "Handles Redo command.";
      }
    }

    public override string Name
    {
      get
      {
        return "Redo Command Handler";
      }
    }


    #endregion


    #region Methods


    protected override void OnStateChnaged()
    {
      if (State == FrameworkComponentState.Initialized)
      {
        _historyService = (EditingHistoryService)WtfFramework.Instance.Services[typeof(EditingHistoryService)];
      }
      else
      {
        _historyService = null;
      }
    }


    protected override void OnUnload()
    {
    }


    protected override FrameworkComponentState OnInitialize()
    {
      return FrameworkComponentState.Initialized;
    }


    protected override FrameworkComponentState OnLoad()
    {
      AddDependency(typeof(EditingHistoryService));

      return FrameworkComponentState.Loaded;
    }


    public bool CanExecuteCommand(object sender, object parameter)
    {
      if (_historyService == null)
      {
        return false;
      }

      return _historyService.CanRedo;
    }


    public void ExecuteCommand(object sender, object parameter)
    {
      _historyService.Redo();
    }


    #endregion
  }
}